package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.ruoyi.system.domain.Comment_que;
import com.ruoyi.system.domain.dto.CommentDTO;
import com.ruoyi.system.service.comment_que_Service;
import com.ruoyi.web.controller.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class Comment_queController {
    @Autowired
    private comment_que_Service commentService;

    //查找评论及二级评论
    @GetMapping("/comments")
    public R<List<CommentDTO>> comments(@RequestBody  List<CommentDTO> commentDTO){


        return R.success(commentService.findFather(commentDTO));
    }
    //评论的分页查询
    @PostMapping("/commentPage")
    public R<Page> pageR(@RequestParam int page,@RequestParam int pageSize){
        Page<Comment_que> pageInfo = new Page<>(page,pageSize);
        //条件构造器
        LambdaQueryWrapper<Comment_que> queryWrapper = new LambdaQueryWrapper<>();
        //添加排序条件，根据id进行排序
        queryWrapper.orderByAsc(Comment_que::getCreateTime);
        commentService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }
    //评论删除
    @DeleteMapping("/deleteComment")
    public R<String> deleteComment(@RequestParam int commentId){
        commentService.removeById(commentId);
        return R.success("删除成功");
    }
    //添加评论
    @PostMapping("/insertComment")
    public R<String> insertComment(@RequestBody  Comment_que comment){
        commentService.save(comment);
        return R.success("添加成功");
    }








}
